package com.txc.common.utils.supply;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.txc.common.global.result.Result;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;


import java.io.IOException;

/**
 * @ClassName: ResponseUtil
 * @Author: TXC
 * @Date: 2023-07-30 14:24
 **/
public class HttpServletResponseUtil {
    public static void out(HttpServletResponse response, Result<?> result) {
        response.setContentType(MediaType.APPLICATION_JSON_VALUE);
        response.setStatus(HttpStatus.OK.value());
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            objectMapper.writeValue(response.getOutputStream(), result);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
